USE [ShortenUrl]
GO

/****** Object:  Table [dbo].[ShortenClicks]    Script Date: 11/14/2012 16:41:09 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ShortenClicks]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[ShortenClicks](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[UrlId] [int] NOT NULL,
	[Clicks] [int] NOT NULL,
 CONSTRAINT [PK_ShortenClicks] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ShortenClicks_ShortenUrls]') AND parent_object_id = OBJECT_ID(N'[dbo].[ShortenClicks]'))
ALTER TABLE [dbo].[ShortenClicks]  WITH CHECK ADD  CONSTRAINT [FK_ShortenClicks_ShortenUrls] FOREIGN KEY([UrlId])
REFERENCES [dbo].[ShortenUrls] ([Id])
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_ShortenClicks_ShortenUrls]') AND parent_object_id = OBJECT_ID(N'[dbo].[ShortenClicks]'))
ALTER TABLE [dbo].[ShortenClicks] CHECK CONSTRAINT [FK_ShortenClicks_ShortenUrls]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_ShortenClicks_Clicks]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[ShortenClicks] ADD  CONSTRAINT [DF_ShortenClicks_Clicks]  DEFAULT ((0)) FOR [Clicks]
END

GO


